<?php
declare (strict_types = 1);

namespace app\controller;

use app\facade\Param;
use app\helpers\api\ApiResponse;
use app\model\Plan;
use think\Request;

class PlanController
{
    use ApiResponse;
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index(Request $request)
    {
        $query = Plan::order('id', 'desc');
        $query = Param::planParam($request->param(), $query);
        return $this->success($query->paginate($request->param('page_size', 15)));
    }

    /**
     * 获取详情
     */
    public function show(Plan $plan)
    {
        return $this->success($plan);
    }

    /**
     * @param Request $request
     * @return mixed
     */
    public function store(Request $request)
    {
        Plan::create($request->param());
        return $this->created();
    }

    /**
     * 保存新建的资源
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save(Request $request, Plan $plan)
    {
        $plan->update($request->param());
        return  $this->update();
    }

    /**
     * 删除
     * @param Plan $plan
     * @return mixed
     */
    public function delete(Plan $plan)
    {
        $plan->delete();
        return $this->destroy();
    }

    
}
